<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= content_for?(:title) ? yield(:title) + " - Huginn" : "Huginn" %></title>
    <meta name="description" content="">
    <meta name="author" content="">
    <%= stylesheet_link_tag    "application", :media => "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
    <link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" sizes="16x16">
    <link rel="icon" type="image/png" href="/android-chrome-48x48.png" sizes="48x48">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="manifest" href="/manifest.json">
    <%= yield(:ace_editor_script) %>
    <%= yield(:head) %>
  </head>
  <body>
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <%= render 'layouts/navigation' %>
      </div>
    </nav>

    <div id="main" role="main">
      <div class="container">
        <div class="row">
          <%= render 'layouts/messages' %>
        </div>
      </div>
      <% if user_signed_in? %>
        <%= render "upgrade_warning" %>
      <% end %>

      <div id="main-content">
        <%= yield %>
      </div>
      
    </div>

    <script>
      window.agentPaths = {};
      window.agentNames = [];
      <% if current_user.present? -%>
        var myAgents = <%= Utils.jsonify(current_user.agents.pluck(:name, :id).inject({}) {|m, a| next if a.last.nil?; m[a.first] = agent_path(a.last); m }) %>;
        var myScenarios = <%= Utils.jsonify(current_user.scenarios.pluck(:name, :id).inject({}) {|m, s| m[s.first + " Scenario"] = scenario_path(s.last); m }) %>;
        $.extend(window.agentPaths, myAgents);
        $.extend(window.agentPaths, myScenarios);
        window.agentPaths["All Agents Index"] = <%= Utils.jsonify agents_path %>;
        window.agentPaths["New Agent"] = <%= Utils.jsonify new_agent_path %>;
        window.agentPaths["Account"] = <%= Utils.jsonify edit_user_registration_path %>;
        window.agentPaths["Events Index"] = <%= Utils.jsonify events_path %>;
        window.agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_path %>;
        window.agentPaths["Run Event Propagation"] = { url: <%= Utils.jsonify propagate_agents_path %>, method: 'POST' };

        $.each(window.agentPaths, function(name, v) { window.agentNames.push(name); });
      <% end -%>
    </script>
  </body>
</html>
